"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var api_1 = require("../../../config/api");
var login_service_1 = require("app/lib/service/login.service");
var local_storage_service_1 = require("../../lib/service/local-storage.service");
var LoginData = /** @class */ (function () {
    function LoginData() {
    }
    return LoginData;
}());
exports.LoginData = LoginData;
var RedirectMsg = /** @class */ (function () {
    function RedirectMsg() {
    }
    return RedirectMsg;
}());
exports.RedirectMsg = RedirectMsg;
var PasseditMsg = /** @class */ (function () {
    function PasseditMsg() {
    }
    return PasseditMsg;
}());
exports.PasseditMsg = PasseditMsg;
var forgetPsdComponent = /** @class */ (function () {
    function forgetPsdComponent(loginService, route, localStorageService) {
        this.loginService = loginService;
        this.route = route;
        this.localStorageService = localStorageService;
        this.loginData = new LoginData();
        this.redirectMsg = new RedirectMsg();
        this.passeditMsg = new PasseditMsg();
        this.redirectSmsSendTime = 0;
    }
    forgetPsdComponent.prototype.ngOnInit = function () {
        this.vCode();
    };
    forgetPsdComponent.prototype.login = function () {
        var _this = this;
        this.loginService.doLogin(this.passeditMsg.mobile, this.passeditMsg.password).subscribe(function (rs) {
            if (rs.code === 2000) {
                _this.loginData = rs;
                var time = new Date(rs.time);
                var now_time = time.getTime() / 1000;
                _this.loginData.data.user.time = now_time + '';
                _this.loginData.data.user.a = _this.username;
                _this.loginData.data.user.p = _this.password;
                // 清理之前登录的信息
                _this.localStorageService.clearAll();
                // 保存当前的信息
                _this.localStorageService.setUserInfo(_this.loginData.data.user);
                _this.localStorageService.setToken(_this.loginData.data.token);
                return _this.redirect();
            }
            else {
                alert(rs.message);
            }
        }, function (err) { return console.log(err); });
    };
    forgetPsdComponent.prototype.getPhoneCode = function (type, mobile) {
        var _this = this;
        if (!mobile) {
            return alert('请填写手机号码');
        }
        // 检查图片验证码是否正确
        this.loginService.checkCode(this.passeditMsg.code, this.passeditMsg.table_id).subscribe(function (data) {
            if (data.code === 2000) {
                _this.smsSend(type, mobile);
            }
            else {
                alert(data.message);
                _this.vCode();
            }
        });
    };
    forgetPsdComponent.prototype.smsSend = function (type, mobile) {
        var _this = this;
        this.loginService.smsSend(mobile, type).subscribe(function (res) {
            if (res.code === 2000) {
                _this.redirectSmsSendTime = 60;
                _this.redirectSmsSendTimeLoading();
                alert(res.message);
            }
            else {
                alert(res.message);
            }
        });
    };
    forgetPsdComponent.prototype.redirectSmsSendTimeLoading = function () {
        var _this = this;
        var Loading = setInterval(function () {
            _this.redirectSmsSendTime = _this.redirectSmsSendTime - 1;
            if (!_this.redirectSmsSendTime) {
                clearInterval(Loading);
            }
        }, 1000);
    };
    forgetPsdComponent.prototype.vCode = function () {
        var _this = this;
        this.vUrl = '';
        this.loginService.getTableId().subscribe(function (rs) {
            _this.passeditMsg.table_id = rs.data.table_id;
            _this.vUrl = api_1.adSystemApiUrl + '/v1/common/captcha/get_captcha/' + _this.passeditMsg.table_id;
        }, function (err) { return console.log(err); });
    };
    forgetPsdComponent.prototype.redirect = function () {
        this.route.navigate(['/main/index']);
    };
    // 确认修改密码
    forgetPsdComponent.prototype.passedit = function () {
        var _this = this;
        this.loginService.passedit(this.passeditMsg).subscribe(function (res) {
            if (res.code === 2000) {
                alert(res.message);
                _this.login();
            }
            else {
                alert(res.message);
            }
        });
    };
    forgetPsdComponent = __decorate([
        core_1.Component({
            selector: 'app-forgetPsd',
            templateUrl: 'forgetPsd.component.html',
            styleUrls: ['forgetPsd.component.scss'],
            providers: [login_service_1.LoginService, local_storage_service_1.LocalStorageService],
        })
    ], forgetPsdComponent);
    return forgetPsdComponent;
}());
exports.forgetPsdComponent = forgetPsdComponent;
